<?php

namespace Rblog\Module\Admin\Controller;

class Setup extends Index {
    private $_model;
    
    public function __construct() {
        $this->_working = 'setup';
        parent::__construct();
        $this->_model = \Rexzy::model( 'Setup' );
    }
    
    /**
     * 显示设置表格和保存设置
     */
    public function set() {
        if ( $this->request->isPost() != true ) {
            $setval = $this->_model->get();
            $this->view->assign( 'setval', $setval );
            $this->view->display();
            
        } else {
            $post = $this->request->AllInput( 'p' );
            
            $data = array(
                'title' => array(
                    'val' => trim( $post['title'] ),
                    'message' => '请输入站点名称'
                ),
                'siteUrl' => array(
                    'val' => trim( $post['siteUrl'] ),
                    'message' => '请输入站点地址'
                ),
                'description' => array( 
                    'val' => trim( $post['description'] ),
                    'message' => '请输入站点描述'
                ),
                'keywords' => array( 
                    'val' => trim( $post['keywords'] ),
                    'message' => '请输入关键词'
                )
            );
            
            $setting = function( $val ) {
                return $this->_model->seting( $val );
            };
            
            echo json_encode( $this->formCheck( $data, $setting ) );
        }
    }
}

